/**
 * Copyright (C), 2012-2018, 联奕科技有限公司
 * FileName: ValidateCodeController
 * Author:   石贵武
 * Date:     2018\3\9 0009 10:07
 * Description: 图形验证码校验
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhoudongxiu.security.core.vaildators.controller;

import com.zhoudongxiu.security.core.constants.SecurityConstants;
import com.zhoudongxiu.security.core.sms.SmsCodeSender;
import com.zhoudongxiu.security.core.vaildators.code.ImageCode;
import com.zhoudongxiu.security.core.vaildators.code.ValidateCode;
import com.zhoudongxiu.security.core.vaildators.generator.ValidateCodeGenerator;
import com.zhoudongxiu.security.core.vaildators.processor.ValidateCodeProcessorHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.web.HttpSessionSessionStrategy;
import org.springframework.social.connect.web.SessionStrategy;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 〈一句话功能简述〉<br>
 * 〈图形验证码校验〉
 *
 * @author 石贵武
 * @create 2018\3\9 0009
 * @since 1.0.0
 */
@RestController
@Slf4j
public class ValidateCodeController {

    @Autowired
    private ValidateCodeProcessorHolder validateCodeProcessorHolder;

    /**
     * 创建验证码，根据验证码类型不同，调用不同的 {@link ValidateCodeProcessor}接口实现
     *
     * @param request
     * @param response
     * @param type
     * @throws Exception
     */
    @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{type}")
    public void createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable String type)
            throws Exception {
        validateCodeProcessorHolder.findValidateCodeProcessor(type).create(new ServletWebRequest(request, response));
    }





}